<template>
  <el-dialog
    v-el-drag-dialog="{updataFull, updataDialogWidth}"
    :fullscreen="isfullscreen"
    :width="setDialogWidth('450px')"
    :title="$t('USER_INFO')"
    :visible="visible"
    @open="open"
    @close="$emit('close')"
  >
    <el-form v-loading="loading" label-width="100px">
      <el-form-item :label="$t('AVATAR') + '：'">
        <avatar-cropper ref="avatarCropper" />
      </el-form-item>
      <el-form-item :label="$t('USER_ID') + '：'">
        {{ userInfo.userId }}
      </el-form-item>
      <el-form-item :label="$t('REAL_NAME') + '：'">
        {{ userInfo.realName }}
      </el-form-item>
      <el-form-item :label="$t('GENDER') + '：'">
        {{ userInfo.gender }}
      </el-form-item>
      <el-form-item :label="$t('BIRTHDAY') + '：'">
        {{ userInfo.birthday }}
      </el-form-item>
      <el-form-item :label="$t('ADDRESS') + '：'">
        {{ userInfo.address }}
      </el-form-item>
      <el-form-item :label="$t('PHONE') + '：'">
        {{ userInfo.phone }}
      </el-form-item>
      <el-form-item :label="$t('EMAIL') + '：'">
        {{ userInfo.email }}
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
  import { mapGetters } from 'vuex'
  import AvatarCropper from './AvatarCropper'
  import UserApi from '@/api/system/UserApi'

  export default {
    components: {
      AvatarCropper
    },
    props: {
      visible: Boolean
    },
    data() {
      return {
        userInfo: {},
        loading: false
      }
    },
    computed: {
      ...mapGetters(['getUserId'])
    },
    methods: {
      open() {
        this.userInfo = {}
        this.loading = true
        UserApi.getUser(this.getUserId).then(res => {
          this.userInfo = res || {}
        }).finally(e => {
          this.loading = false
        })
      },
      uploadImg() {
        this.$refs.uploadCropper.uploadImg()
      }
    }
  }
</script>

<style scoped>
.el-dialog__wrapper {
  line-height: 0px;
}

.el-dialog__wrapper :deep(.el-dialog__body) {
  padding: 20px;
}

.el-dialog__wrapper :deep(.el-form-item) {
  margin-bottom: 10px;
}
</style>
